/*
 * @Description:
 * @Autor: Yao
 * @Date: 2020-04-01 11:29:12
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-04-03 15:07:00
 */

//  导出components文件夹下的index.vue,index.js的组件，不包括子文件夹
let files = require.context('./components', true, /index\.(js)$/)

let components = {}

files.keys().forEach((el) => {
  // console.log(el)
  let name =
    files(el).default.name ||
    el.substring(el.indexOf('/') + 1, el.lastIndexOf('/'))
  !files(el).default.install &&
    (files(el).default.install = function(vue) {
      vue.component(name, files(el).default)
    })
  components[name] = files(el).default
})

components.install = function(vue) {
  Object.keys(components).forEach((el) => {
    if (el !== 'install') {
      components[el].install(vue)
    }
  })
}
module.exports = components
